/*
 * Created by JFormDesigner on Wed May 25 23:05:24 CST 2022
 */

package jw3.c2.view;

import java.awt.event.*;

import jw3.c2.controller.AccountController;
import jw3.c2.controller.OpensController;

import java.awt.*;
import java.util.Vector;
import javax.swing.*;
import javax.swing.table.*;

/**
 * @author Brainrain
 */
public class Bill extends JFrame {
    public Bill() {
        initComponents();
        this.setVisible(true);
        this.setSize(800,600);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }
    private void showData(String account){
        //1、表头
        Vector<Object> heads=new Vector<Object>();
        heads.add("编号");
        heads.add("账单号");
        heads.add("客户编号");
        heads.add("房间编号");
        heads.add("结账时间");
        heads.add("应收金额");
        heads.add("实收金额");

        //2、表数据
//        Vector<Vector<Object>> data= OpensController.getAll();
        data= OpensController.getAll(account);
        DefaultTableModel dtm=new DefaultTableModel(data,heads);
        table1.setModel(dtm);

    }


    private void showData2(String opens){
        //1、表头
        Vector<Object> heads=new Vector<Object>();
        heads.add("编号");
        heads.add("VIP编号");
        heads.add("姓名");
        heads.add("性别");
        heads.add("电话号码");
        heads.add("证件号码");
        heads.add("地址");
        heads.add("开房状态");
        heads.add("开房日期");
        heads.add("开房天数");
        heads.add("房间类型");
        heads.add("离开时间");
        heads.add("离开天数");

        //2、表数据
//        Vector<Vector<Object>> data= OpensController.getAll();
        data= OpensController.getAll(opens);
        DefaultTableModel dtm=new DefaultTableModel(data,heads);
        table2.setModel(dtm);

    }

    private void button2MouseClicked(MouseEvent e) {
        // TODO add your code here
        showData(textField1.getText());
    }
// 第一个窗口刷新
    private void button1MouseClicked(MouseEvent e) {
        // TODO add your code here
        showData(textField1.getText());
    }

    private void button3MouseClicked(MouseEvent e) {
        // TODO add your code here
        this.panel1.setVisible(true);
        this.panel4.setVisible(false);
        AccountController accountController=new AccountController();
    }

    private void button4MouseClicked(MouseEvent e) {
        // TODO add your code here
        this.panel1.setVisible(false);
        this.panel4.setVisible(true);
    }

    private void button8MouseClicked(MouseEvent e) {
        // TODO add your code here
        showData2(textField3.getText());
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        button4 = new JButton();
        button5 = new JButton();
        button6 = new JButton();
        panel1 = new JPanel();
        label2 = new JLabel();
        textField1 = new JTextField();
        label5 = new JLabel();
        textField2 = new JTextField();
        button1 = new JButton();
        button2 = new JButton();
        label6 = new JLabel();
        panel2 = new JPanel();
        scrollPane1 = new JScrollPane();
        table1 = new JTable();
        panel4 = new JPanel();
        label3 = new JLabel();
        button9 = new JButton();
        button8 = new JButton();
        textField3 = new JTextField();
        label1 = new JLabel();
        scrollPane2 = new JScrollPane();
        table2 = new JTable();
        button3 = new JButton();

        //======== this ========
        setTitle("\u8425\u4e1a\u67e5\u8be2");
        Container contentPane = getContentPane();
        contentPane.setLayout(null);

        //---- button4 ----
        button4.setText("\u5168\u90e8\u5bbe\u5ba2\u4fe1\u606f\u67e5\u8be2");
        button4.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                button4MouseClicked(e);
            }
        });
        contentPane.add(button4);
        button4.setBounds(270, 5, 125, 34);

        //---- button5 ----
        button5.setText("\u5728\u5e97\u5bbe\u5ba2\u6d88\u8d39\u67e5\u8be2");
        contentPane.add(button5);
        button5.setBounds(425, 5, 130, 34);

        //---- button6 ----
        button6.setText("\u79bb\u5e97\u5bbe\u5ba2\u6d88\u8d39\u67e5\u8be2");
        contentPane.add(button6);
        button6.setBounds(590, 5, 120, 34);

        //======== panel1 ========
        {
            panel1.setBackground(Color.white);
            panel1.setVisible(false);
            panel1.setLayout(null);

            //---- label2 ----
            label2.setText("\u7ed3\u8d26\u65f6\u95f4\uff1a");
            panel1.add(label2);
            label2.setBounds(35, 0, 115, label2.getPreferredSize().height);
            panel1.add(textField1);
            textField1.setBounds(150, 0, 125, textField1.getPreferredSize().height);

            //---- label5 ----
            label5.setText("\u8d26\u5355\u53f7");
            panel1.add(label5);
            label5.setBounds(40, 35, 85, label5.getPreferredSize().height);
            panel1.add(textField2);
            textField2.setBounds(150, 30, 125, textField2.getPreferredSize().height);

            //---- button1 ----
            button1.setText("\u67e5\u8be2");
            button1.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    button1MouseClicked(e);
                }
            });
            panel1.add(button1);
            button1.setBounds(new Rectangle(new Point(320, 40), button1.getPreferredSize()));

            //---- button2 ----
            button2.setText("\u5237\u65b0");
            button2.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    button2MouseClicked(e);
                }
            });
            panel1.add(button2);
            button2.setBounds(new Rectangle(new Point(425, 40), button2.getPreferredSize()));

            //---- label6 ----
            label6.setText("   \u7ed3\u8d26\u72b6\u6001\u4fe1\u606f");
            label6.setBackground(new Color(204, 255, 204));
            panel1.add(label6);
            label6.setBounds(255, 80, 105, 35);

            //======== panel2 ========
            {
                panel2.setBackground(new Color(153, 255, 204));
                panel2.setLayout(null);

                //======== scrollPane1 ========
                {

                    //---- table1 ----
                    table1.setModel(new DefaultTableModel(
                        new Object[][] {
                            {null, null, null, null, null, null},
                            {null, null, null, null, null, null},
                            {null, null, null, null, null, null},
                            {null, null, null, null, null, null},
                            {null, null, null, null, null, null},
                            {null, null, null, null, null, null},
                        },
                        new String[] {
                            null, null, null, null, null, null
                        }
                    ));
                    scrollPane1.setViewportView(table1);
                }
                panel2.add(scrollPane1);
                scrollPane1.setBounds(-15, 0, 790, 495);

                {
                    // compute preferred size
                    Dimension preferredSize = new Dimension();
                    for(int i = 0; i < panel2.getComponentCount(); i++) {
                        Rectangle bounds = panel2.getComponent(i).getBounds();
                        preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                        preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                    }
                    Insets insets = panel2.getInsets();
                    preferredSize.width += insets.right;
                    preferredSize.height += insets.bottom;
                    panel2.setMinimumSize(preferredSize);
                    panel2.setPreferredSize(preferredSize);
                }
            }
            panel1.add(panel2);
            panel2.setBounds(20, 120, 880, 695);
        }
        contentPane.add(panel1);
        panel1.setBounds(0, 50, 820, 345);

        //======== panel4 ========
        {
            panel4.setLayout(null);

            //---- label3 ----
            label3.setText("\u6240\u6709\u6765\u5bbe\u4fe1\u606f");
            panel4.add(label3);
            label3.setBounds(305, 90, 185, 22);

            //---- button9 ----
            button9.setText("\u5237\u65b0");
            panel4.add(button9);
            button9.setBounds(new Rectangle(new Point(435, 50), button9.getPreferredSize()));

            //---- button8 ----
            button8.setText("\u67e5\u8be2");
            button8.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    button8MouseClicked(e);
                }
            });
            panel4.add(button8);
            button8.setBounds(new Rectangle(new Point(315, 50), button8.getPreferredSize()));
            panel4.add(textField3);
            textField3.setBounds(185, 15, 125, 30);

            //---- label1 ----
            label1.setText("\u5bbe\u5ba2\u59d3\u540d/\u8bc1\u4ef6\u7f16\u53f7/\u623f\u95f4\u53f7\uff1a");
            panel4.add(label1);
            label1.setBounds(10, 10, 180, 40);

            {
                // compute preferred size
                Dimension preferredSize = new Dimension();
                for(int i = 0; i < panel4.getComponentCount(); i++) {
                    Rectangle bounds = panel4.getComponent(i).getBounds();
                    preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                    preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                }
                Insets insets = panel4.getInsets();
                preferredSize.width += insets.right;
                preferredSize.height += insets.bottom;
                panel4.setMinimumSize(preferredSize);
                panel4.setPreferredSize(preferredSize);
            }
        }
        contentPane.add(panel4);
        panel4.setBounds(0, 40, 630, 125);

        //======== scrollPane2 ========
        {

            //---- table2 ----
            table2.setModel(new DefaultTableModel(
                new Object[][] {
                    {null, null, null, null, null, null, null, null, null, null, null, null, null},
                    {null, null, null, null, null, null, null, null, null, null, null, null, null},
                    {null, null, null, null, null, null, null, null, null, null, null, null, null},
                    {null, null, null, null, null, null, null, null, null, null, null, null, null},
                    {null, null, null, null, null, null, null, null, null, null, null, null, null},
                    {null, null, null, null, null, null, null, null, null, null, null, null, null},
                },
                new String[] {
                    null, null, null, null, null, null, null, null, null, null, null, null, null
                }
            ));
            scrollPane2.setViewportView(table2);
        }
        contentPane.add(scrollPane2);
        scrollPane2.setBounds(0, 160, 760, scrollPane2.getPreferredSize().height);

        //---- button3 ----
        button3.setText("\u7ed3\u8d26\u67e5\u8be2");
        button3.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                button3MouseClicked(e);
            }
        });
        contentPane.add(button3);
        button3.setBounds(105, 5, 115, button3.getPreferredSize().height);

        contentPane.setPreferredSize(new Dimension(755, 410));
        pack();
        setLocationRelativeTo(null);
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JButton button4;
    private JButton button5;
    private JButton button6;
    private JPanel panel1;
    private JLabel label2;
    private JTextField textField1;
    private JLabel label5;
    private JTextField textField2;
    private JButton button1;
    private JButton button2;
    private JLabel label6;
    private JPanel panel2;
    private JScrollPane scrollPane1;
    private JTable table1;
    private JPanel panel4;
    private JLabel label3;
    private JButton button9;
    private JButton button8;
    private JTextField textField3;
    private JLabel label1;
    private JScrollPane scrollPane2;
    private JTable table2;
    private JButton button3;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
    private static Vector<Vector<Object>> data;
}
